package top.lilele.adminSystem.web;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lilele.adminSystem.dto.AddRoleResourceDao;
import top.lilele.adminSystem.dto.IdParams;
import top.lilele.adminSystem.entity.AdminRoleEntity;
import top.lilele.adminSystem.service.AdminRoleService;
import top.lilele.adminSystem.utils.BaseResponse;
import top.lilele.adminSystem.utils.ResponseCodeEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lilele
 */
@RestController
@RequestMapping(value = "role")
public class AdminRoleController {
    @Resource
    AdminRoleService adminRoleService;

    /**
     * 新增角色信息
     *
     * @param adminRoleEntity
     * @return
     */
    @PostMapping(value = "add")
    private BaseResponse add(@Validated @RequestBody AdminRoleEntity adminRoleEntity) {
        return adminRoleService.add(adminRoleEntity);
    }

    /**
     * 根据id查询角色信息
     *
     * @return
     */
    @PostMapping(value = "queryRoleById")
    private BaseResponse queryRoleById(@RequestBody @Validated IdParams idParams) {
        AdminRoleEntity info = adminRoleService.queryRoleById(idParams.getId());
        return BaseResponse.info(ResponseCodeEnum.Success, info);
    }

    /**
     * 查询角色列表
     *
     * @return
     */
    @PostMapping(value = "queryRoleList")
    private BaseResponse queryRoleList() {
        List<AdminRoleEntity> list = adminRoleService.queryRoleList();
        return BaseResponse.info(ResponseCodeEnum.Success, list);
    }

    /**
     * 根据id更新角色信息
     *
     * @param adminRoleEntity
     * @return
     */
    @PostMapping(value = "updateRoleById")
    private BaseResponse updateRoleById(@RequestBody AdminRoleEntity adminRoleEntity) {
        adminRoleService.updateRoleById(adminRoleEntity);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    /**
     * 根据id删除角色
     *
     * @param idParams
     * @return
     */
    @PostMapping(value = "deleteRoleById")
    private BaseResponse deleteRoleById(@RequestBody @Validated IdParams idParams) {
        adminRoleService.deleteRoleById(idParams.getId());
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    /**
     * 绑定角色-资源
     *
     * @param addRoleResourceDao
     * @return
     */
    @PostMapping(value = "addRoleResource")
    public BaseResponse addRoleResource(@RequestBody AddRoleResourceDao addRoleResourceDao) {
        adminRoleService.addRoleResource(addRoleResourceDao);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }
}
